package com.ruoyi.web.course;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.course.vo.SVideoVo;
import com.ruoyi.course.service.ISVideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 学生视频Controller
 *
 * @author ruoyi
 * @date 2024-12-03
 */
@Api(tags = "学生视频Controller")
@RestController
@RequestMapping("/course/s_video")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SVideoController extends BaseController {

    private final ISVideoService sVideoService;

    @ApiOperation("查询学生视频列表")
    @PreAuthorize("@ss.hasPermi('course:s_video:list')")
    @GetMapping("/list")
    public TableDataInfo<SVideoVo> list(SVideoVo entity) {
        return sVideoService.queryList(entity);
    }

    @ApiOperation("查询学生视频所有列表")
    @GetMapping("/listAll")
    public AjaxResult listAll(SVideoVo entity) {
        return AjaxResult.success("查询成功", sVideoService.queryAll(entity));
    }

    @ApiOperation("导出学生视频列表")
    @PreAuthorize("@ss.hasPermi('course:s_video:export')")
    @Log(title = "学生视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SVideoVo entity) {
        List<SVideoVo> list = sVideoService.queryAll(entity);
        ExcelUtil<SVideoVo> util = new ExcelUtil<>(SVideoVo.class);
        util.exportExcel(response, list, "学生视频数据");
    }

    @ApiOperation("获取学生视频详细信息")
    @PreAuthorize("@ss.hasPermi('course:s_video:query')")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success("查询成功", sVideoService.queryById(id));
    }

    @ApiOperation("新增学生视频")
    @PreAuthorize("@ss.hasPermi('course:s_video:add')")
    @Log(title = "学生视频", businessType = BusinessType.INSERT)
    @PostMapping("add")
    public AjaxResult add(@RequestBody SVideoVo entity) {
        return toAjax(sVideoService.save(entity));
    }

    @ApiOperation("修改学生视频")
    @PreAuthorize("@ss.hasPermi('course:s_video:edit')")
    @Log(title = "学生视频", businessType = BusinessType.UPDATE)
    @PostMapping("edit")
    public AjaxResult edit(@RequestBody SVideoVo entity) {
        return toAjax(sVideoService.updateById(entity));
    }

    @ApiOperation("删除学生视频")
    @PreAuthorize("@ss.hasPermi('course:s_video:remove')")
    @Log(title = "学生视频", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sVideoService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
